package main

import (
	"cloud9lib.googlecode.com/hg/mux"
	"flag"
	"log"
	"http"
	"io/ioutil"
)

func main () {

	flag.Parse()

	if flag.Arg(0) == "quit" {
		resp, err := http.Post(mux.MUX_URL + "/quit", "text/plain", nil)
		defer resp.Body.Close()
		if err != nil {
			panic (err)
		}
		text, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			panic (err)
		}
		log.Println("MUX: ", string(text))
		return
	}

	hostname := flag.Arg(0)
	urlstr := flag.Arg(1)

	err := mux.ListenHostname(hostname, urlstr)

	if err != nil {
		log.Fatal (err)
	}

	log.Println("registered ", hostname, urlstr)
}
